/* 3DGo Game
 * Copyright (C) 2008 Roman Hwang, Eugene Melnichek

 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation - version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#if defined(DEBUG) || defined(_DEBUG)
	#include <crtdbg.h>
#endif

#include <windows.h>
//#pragma comment(lib, "PhantomRunner.lib")
#include "GameEngine.h"

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

extern IDirect3DDevice9* pMyDevice;

GameEngine engine(19);

INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
	// Useful debug stuff for detecting memory leaks
#if defined(DEBUG) || defined(_DEBUG)
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
	engine.Init(hInst, WndProc);
	engine.Run();
	d3d::Release(pMyDevice);
	return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
	case WM_LBUTTONDOWN:
		engine.MouseButtonDown(LOWORD(lParam), HIWORD(lParam), MouseButtons::LeftMouseButton);
		break;
	case WM_LBUTTONUP:
		engine.MouseButtonUp(LOWORD(lParam), HIWORD(lParam), MouseButtons::LeftMouseButton);
		break;
	case WM_ACTIVATE:
		if (LOWORD(wParam) == WA_INACTIVE)
			engine.SetProcessInputState(false);
		else engine.SetProcessInputState(true);
		break;

	case WM_DESTROY:
		::PostQuitMessage(0);
		break;
		
	/*case WM_KEYDOWN:
		if( wParam == VK_ESCAPE )
			::DestroyWindow(hwnd);

		break;*/
	}
	return ::DefWindowProc(hwnd, msg, wParam, lParam);
}